<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../value/value_en.php";
} else if($lang == "VN") {
	include "../value/value_vn.php";
}
else {
	include "../value/value_kr.php";
}
include '../content-accountant/invoicetax.php';
$stonggiacungcap=0;
$stongthue=0;
$stongtien=0;
$arr=array();
if(isset($_SESSION['manginvoicetax'])){
	$arr=$_SESSION['manginvoicetax'];
}
$vtime="";
$status=$_REQUEST['status'];
if($status==0){
	$l_ngaygiaodich=$l_ngaygiaodich0;
	$l_ngayphathanh=$l_ngayphathanh0;	
	$l_thoigiangiaodich=$l_thoigiangiaodich0;
}
if($status==1){
	$l_ngaygiaodich=$l_ngaygiaodich1;
	$l_ngayphathanh=$l_ngayphathanh1;	
	$l_thoigiangiaodich=$l_thoigiangiaodich1;
}
if(isset($_REQUEST['type'])){
	if($_REQUEST['type']=="thang"){
		$ntt=date("t",mktime(0,0,0,$_REQUEST['mon'],1,$_REQUEST['year']));
		if($_REQUEST['mon']<10){
			$vtime=$_REQUEST['year']."-0".$_REQUEST['mon']."-01"." ~ ".$_REQUEST['year']."-0".$_REQUEST['mon']."-".$ntt;
		}else{
			$vtime=$_REQUEST['year']."-".$_REQUEST['mon']."-01"." ~ ".$_REQUEST['year']."-".$_REQUEST['mon']."-".$ntt;
		}
	}else if($_REQUEST['type']=="tinhqui"){
		$mangquy=array(1,1,1,2,2,2,3,3,3,4,4,4);
		$mq=array(1=>array(1,3),2=>array(4,6),3=>array(7,9),4=>array(10,12));
		$ntt=date("t",mktime(0,0,0,$mq[$_REQUEST['qui']][1],1,$_REQUEST['year']));
		if($mq[$_REQUEST['qui']][0]<10){
			$vtime=$_REQUEST['year']."-0".$mq[$_REQUEST['qui']][0]."-01"." ~ ".$_REQUEST['year']."-0".$mq[$_REQUEST['qui']][1]."-".$ntt;
		}else{
			$vtime=$_REQUEST['year']."-".$mq[$_REQUEST['qui']][0]."-01"." ~ ".$_REQUEST['year']."-".$mq[$_REQUEST['qui']][1]."-".$ntt;
		}
	}
	
	
}
$addressbrowser = $_SERVER['SERVER_NAME'];
$temp = explode(".", $addressbrowser);

$typedate=$_REQUEST['typedate'];
if($typedate=='ngayph'){
	$type=$l_phathanh;
}
if($typedate=='ngaygd'){
	$type=$l_giaodich;
}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="../css/style.css" rel="stylesheet" />
<title><?=$l_print?></title>
</head>

<body  onload="window.print();">
<div style="text-align:center;width:100%;font-size:12px;font-family: sans-serif;" >
			<div style="text-align:center;width:100%;">
				<table style="width:100%; text-align:center">
					<tr><td style="font-size:18px;font-weight:bold;"><?=$l_hoadonthue?></td></tr>
				</table>
			</div>
        	<div class="title2">
		    	<span style="float:left"><?php echo $l_company_name?> : <?=strtoupper($temp[0])?></span>
		        <span style="float:right">
		        <?php 
		        if($_REQUEST['cusname']!=""){
		        	?>
		        	<?php echo $l_tenkhachhanggiaodich;?> : <?php echo $_REQUEST['cusname'];?>
		        	<?php 
		        }
		        ?>
		        
		        </span>
		    </div>
		    <div style="clear:both"></div>
		   
		    <?php 
		    if($vtime!=""){
		    	?>
		    	<div style="padding-top:10px;padding-bottom:20px; font-size:14px;font-weight:bold;">
		    		<span style="float:left"><?php echo $l_thoigiangiaodich;?> : <?php echo $vtime;?></span> 
		    	</div>
		    	<?php 
		    }
		    ?>
			
        	<div style="position:relative">
			        	<table cellpadding="0" cellspacing="1"  style="width:100%;border:1px #000000 solid;"  >
				            <tr style="background:#EEEEEE;font-weight:bold;text-align:center;border-bottom:1px #000000 solid;">
				                <th style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_no?></th>
				                <th style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_ngaythangnam?></th>
				                <th style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_company_name?></th>
				                <th width="30%" style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_product_item?></th>
				                <th style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_quantity?></th>
				                <th style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_Supply_price?></th>
				                <th style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_price_vat?></th>
				                <th style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_amount?></th>
				                <th style="border-left: 1px #000000 dotted;border-right: 1px #000000 dotted;border-bottom: 1px #000000 dotted"><?=$l_thoigiangiaodich?></th>
				            </tr>
				           
				           <?php 
				           $soluong=count($arr);
				           if($soluong>0){
				           		$vitri=0;
				           		foreach($arr as $thoigian=>$mgiatri){
				           			$tonggiacungcap=0;
				           			$tongthue=0;
				           			$tongtien=0;
				           			$dem=count($mgiatri);
				           			//echo "<br><br>".$dem;		
				           			if($dem>0){
				           				for($i=0;$i<$dem;$i++){
				           					//echo "<br>".$i;
				           					$inobject= unserialize (serialize ($mgiatri[$i]));
				           					
				           ?>
								            <tr>
								                <td style="padding: 5px;border: 1px #000000 dotted" ><?=($vitri+1)?></td>
								                <td  style="border: 1px #000000 dotted"><?=$inobject->ordertime?></td>
								                <td style="text-align:left;border: 1px #000000 dotted"><?=$inobject->cusname?></td>
								                <td style="text-align:left;border: 1px #000000 dotted"><?=$inobject->order_content?></td>
								                <td  style="border: 1px #000000 dotted"><?=number_format($inobject->order_quantity)?></td>
								                <td style="text-align:right;border: 1px #000000 dotted"><?=number_format($inobject->order_suplly_rice)?></td>
								                <td style="text-align:right;border: 1px #000000 dotted"><?=number_format($inobject->order_tax)?></td>
								                <td style="text-align:right;border: 1px #000000 dotted"><?=number_format($inobject->order_total)?></td>
								                <td  style="border: 1px #000000 dotted"><?=$inobject->order_time_transaction?></td>
								            </tr>
						            <?php 
						            		$tonggiacungcap +=$inobject->order_suplly_rice;
						            		$tongthue +=$inobject->order_tax;
						            		$tongtien +=$inobject->order_total;
						            		$vitri++;
				           				}
				           			}
				           			?>
						            <tr class="coltr2" style="font-weight:bold;font-size:14px;">
						                <td colspan="4"  style="padding: 10px;border: 1px #000000 dotted">
											<?php 
												if($_REQUEST['type']=="thang"){
													?>
													<?php echo $l_month;?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type;?> : <font color="blue"><?php echo number_format($dem);?></font> 
													<?php 
												}else if($_REQUEST['type']=="tinhqui"){
													?>
													<?php echo $l_month;?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type;?> : <font color="blue"><?php echo number_format($dem);?></font> 
													<?php 
												}else{
													?>
													<?php echo $l_days;?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type;?> : <font color="blue"><?php echo number_format($dem);?></font> 
													<?php 
												}
											?>
										</td>
						                <td  style="border: 1px #000000 dotted"></td>
						                <td style="text-align:right;border: 1px #000000 dotted"><?php echo number_format($tonggiacungcap);?></td>
						                <td style="text-align:right;border: 1px #000000 dotted"><?php echo number_format($tongthue);?></td>
						                <td style="text-align:right;border: 1px #000000 dotted"><?php echo number_format($tongtien);?></td>
						                <td style="border: 1px #000000 dotted"></td>
						            </tr>
				           <?php 
				           			$stonggiacungcap +=$tonggiacungcap;
				           			$stongthue +=$tongthue;
				           			$stongtien +=$tongtien;
				           			
				           		}
				           }else{
				           ?>
				            <tr><td colspan="9" style="height:30px;text-align:left;padding-left:20px;"><?php echo $l_list_emplty;?></td></tr>
				           <?php 
				           }
				           ?>
				            
				            <tr style="font-weight:bold;font-size:15px;color:green;">
				                <td colspan="4" style="padding: 10px;border: 1px #000000 dotted"><?php echo $l_tongdon?></td>
				                <td style="border: 1px #000000 dotted"></td>
				                <td style="text-align:right;border: 1px #000000 dotted"><?php echo number_format($stonggiacungcap);?></td>
				                <td style="text-align:right;border: 1px #000000 dotted"><?php echo number_format($stongthue);?></td>
				                <td style="text-align:right;border: 1px #000000 dotted"><?php echo number_format($stongtien);?></td>
				                <td style="text-align:right;border: 1px #000000 dotted"></td>
				            </tr>
				        </table>
			        </div>
        </div>
</body>
</html>